<template>
  <div class="main-wrap" style="padding-top: 10px">
    <el-card class="box-card">
      <Classify @e-emit="handleClick" />
      <TopicItem :tableData="tableData" />
      <Pagination
        v-show="parseInt(pageObj.count) > 0"
        :total="parseInt(pageObj.count)"
        @change="getList"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
      />
    </el-card>
  </div>
</template>
<script>
export default {
  components: {
    Classify: () => import('./Classify.vue'),
    TopicItem: () => import('./TopicItem.vue'),
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        classifyId: '',
        status: '1',
        auditStatus: '2',
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    this.getList()
    this.$bus.$on('queryManTopic', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('queryManTopic')
  },
  methods: {
    async getList() {
      let res = await this.$store.dispatch('queryBbsTopic', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
    },
    handleClick(id) {
      this.listQuery.classifyId = id
      // this.listQuery.title = ''
      this.getList()
    },
  },
}
</script>
<style scoped lang="scss">
.bbs-classify {
  padding: 10px;
  margin-bottom: 20px;
  border-radius: 5px;
  background-color: #ecf5ff50;
  .classify-item {
    margin-right: 10px;
    cursor: pointer;
  }
}
</style>